package com.example.echarts.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class Config implements WebMvcConfigurer {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("GET","POST","HEAD","PUT","DELETE")
                    .allowCredentials(true)
                    .maxAge(3600)
                    .allowedHeaders("*");
        }
    @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {// 将url为 /static/** 的请求映射到 /static/ 路径下进行查找
      registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
  }

}
